/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package carne;

import Model.Carne;
import Model.Mensalidade;
import Model.PersonFormatter;
import Model.Pessoa;
import Utilitarios.Mensagens;
import com.towel.combo.swing.ObjectComboBoxModel;
import com.towel.el.annotation.AnnotationResolver;
import com.towel.swing.table.ObjectTableModel;
import controller.facade.sessionFacadeImplements.SessionFacadeAlterarImplements;
import controller.facade.sessionFacadeImplements.SessionFacadeBuscarImplements;
import controller.facade.sessionFacadeImplements.SessionFacadeCadastrarImplements;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.swing.ComboBoxModel;
import javax.swing.JTable;
import javax.swing.table.TableModel;

/**
 *
 * @author User
 */
public class CadastroDeCarne extends javax.swing.JPanel {

    private ObjectComboBoxModel<Pessoa> modelSacados;
    private ObjectComboBoxModel<Pessoa> modelAlunos;
    private Carne carne;
    private AnnotationResolver resolver;
    private ObjectTableModel<Mensalidade> tableModel;
    SessionFacadeBuscarImplements facadeBuscar = new SessionFacadeBuscarImplements();
    private List<Pessoa> sacados = facadeBuscar.buscarTodosSacado("idPessoa", Pessoa.class);
    private List<Pessoa> alunos = facadeBuscar.buscarTodosAluno("idPessoa", Pessoa.class);

    public ComboBoxModel getModelSacados() {
        modelSacados = new ObjectComboBoxModel<Pessoa>();
        modelSacados.setFormatter(new PersonFormatter());
        modelSacados.setData(sacados);
        return modelSacados;
    }

    public ComboBoxModel getModelAlunos() {
        modelAlunos = new ObjectComboBoxModel<Pessoa>();
        modelAlunos.setFormatter(new PersonFormatter());
        modelAlunos.setData(alunos);
        return modelAlunos;
    }

    /**
     * Creates new form CadastroDePessoa
     */
    public CadastroDeCarne(Carne carne) {
        if (carne != null) {
            this.carne = carne;
            carregaCampos();
        }
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlMensalidades = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        txtValorTotal = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        txtNumeroDePrestacoes = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        txtDataDoVencimento = new javax.swing.JTextField();
        jButton2 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblMensalidades = new javax.swing.JTable();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        txtId = new javax.swing.JTextField();
        txtNumeroContrato = new javax.swing.JTextField();
        txtDescricao = new javax.swing.JTextField();
        txtMensagem = new javax.swing.JTextField();
        txtDataEmissao = new javax.swing.JTextField();
        comboAluno = new javax.swing.JComboBox();
        comboSacado = new javax.swing.JComboBox();
        jPanel3 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();

        jLabel11.setText("Prestações:");

        jLabel5.setText("Valor Total do Carne:");

        jLabel7.setText("Numero de Prestaçõs:");

        jLabel12.setText("Dia do Vencimento:");

        jButton2.setText("Gerar Prestações");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        tblMensalidades.setModel(getModel());
        jScrollPane1.setViewportView(tblMensalidades);

        javax.swing.GroupLayout pnlMensalidadesLayout = new javax.swing.GroupLayout(pnlMensalidades);
        pnlMensalidades.setLayout(pnlMensalidadesLayout);
        pnlMensalidadesLayout.setHorizontalGroup(
            pnlMensalidadesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlMensalidadesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlMensalidadesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlMensalidadesLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jScrollPane1))
                    .addGroup(pnlMensalidadesLayout.createSequentialGroup()
                        .addGroup(pnlMensalidadesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel11)
                            .addGroup(pnlMensalidadesLayout.createSequentialGroup()
                                .addGroup(pnlMensalidadesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel5)
                                    .addComponent(jLabel7)
                                    .addComponent(jLabel12))
                                .addGap(30, 30, 30)
                                .addGroup(pnlMensalidadesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(txtValorTotal)
                                    .addComponent(txtNumeroDePrestacoes, javax.swing.GroupLayout.DEFAULT_SIZE, 114, Short.MAX_VALUE)
                                    .addComponent(txtDataDoVencimento)))
                            .addComponent(jButton2))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        pnlMensalidadesLayout.setVerticalGroup(
            pnlMensalidadesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlMensalidadesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlMensalidadesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtValorTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlMensalidadesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(txtNumeroDePrestacoes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlMensalidadesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(txtDataDoVencimento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel1.setText("Id:");

        jLabel4.setText("Data de Emissão:");

        jLabel3.setText("Mensagem:");

        jLabel2.setText("Numero do Contrato:");

        jLabel6.setText("Descrição:");

        jLabel8.setText("Sacado:");

        jLabel9.setText("Aluno:");

        txtId.setEditable(false);

        txtDataEmissao.setEditable(false);

        comboAluno.setModel(getModelAlunos());

        comboSacado.setModel(getModelSacados());

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel4)
                            .addComponent(jLabel3)
                            .addComponent(jLabel6))
                        .addGap(37, 37, 37)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtDescricao)
                            .addComponent(txtMensagem, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtId, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(txtDataEmissao, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(0, 374, Short.MAX_VALUE))))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel9)
                            .addComponent(jLabel8))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(comboAluno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtNumeroContrato, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(comboSacado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtNumeroContrato, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(comboAluno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(comboSacado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(txtDescricao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtMensagem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtDataEmissao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jButton1.setText("Gravar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton3.setText("Cancelar");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton3)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton3))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(pnlMensalidades, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(17, Short.MAX_VALUE)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(13, 13, 13)
                .addComponent(pnlMensalidades, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(213, 213, 213))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        if (carne == null) {
            try {
                gravarPessoa();
            } catch (Exception ex) {
                Mensagens.Erro("Erro ao gravar: " + ex.getMessage());
            }
        } else {
            try {
                alterarPessoa();
            } catch (Exception ex) {
                Mensagens.Erro("Erro ao alterar: " + ex.getMessage());
            }
        }
        carregaCampos();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        Main.principal.setTela(null);
    }//GEN-LAST:event_jButton3ActionPerformed
    private TableModel getModel() {
        resolver = new AnnotationResolver(Mensalidade.class);
        tableModel = new ObjectTableModel<Mensalidade>(resolver, "valor,paga,dataVencimento,dataPagamento");
        return tableModel;
    }
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        int numero = Integer.parseInt(txtNumeroDePrestacoes.getText());
        double valorTotal = Double.parseDouble(txtValorTotal.getText());
        double valorParcela = valorTotal / numero;

        tblMensalidades = new JTable(tableModel);
        List<Mensalidade> list = new ArrayList<Mensalidade>();
        for (int i = 0; i < numero; i++) {
            Mensalidade m = new Mensalidade(BigDecimal.valueOf(valorParcela), false, new Date(), null, this.carne);
            list.add(m);
        }
        tableModel.setData(list);
    }//GEN-LAST:event_jButton2ActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox comboAluno;
    private javax.swing.JComboBox comboSacado;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel pnlMensalidades;
    private javax.swing.JTable tblMensalidades;
    private javax.swing.JTextField txtDataDoVencimento;
    private javax.swing.JTextField txtDataEmissao;
    private javax.swing.JTextField txtDescricao;
    private javax.swing.JTextField txtId;
    private javax.swing.JTextField txtMensagem;
    private javax.swing.JTextField txtNumeroContrato;
    private javax.swing.JTextField txtNumeroDePrestacoes;
    private javax.swing.JTextField txtValorTotal;
    // End of variables declaration//GEN-END:variables

    private void carregaCampos() {
        txtId.setText(String.valueOf(carne.getIdCarne()));
        txtNumeroContrato.setText(String.valueOf(carne.getNumeroContrato()));
        modelSacados.setSelectedObject(carne.getSacado());
        modelAlunos.setSelectedObject(carne.getAluno());
        txtDescricao.setText(carne.getDescricao());
        txtMensagem.setText(carne.getMensagem());
        txtDataEmissao.setText(carne.getDataEmissao().toString());
        txtValorTotal.setText(String.valueOf(carne.getValorTotal()));
        txtNumeroDePrestacoes.setText(carne.getNumeroDePrestacoes());
        txtDataDoVencimento.setText(carne.getDiaVencimento());
        tableModel.setData(carne.getPrestacaoList());
    }

    private void gravarPessoa() throws Exception {
        this.carne = new Carne(new BigInteger(txtNumeroContrato.getText()),
                new BigDecimal(txtValorTotal.getText()),
                txtNumeroDePrestacoes.getText(),
                txtDataDoVencimento.getText(),
                txtDescricao.getText(),
                txtDescricao.getText(),
                modelSacados.getSelectedObject(),
                modelAlunos.getSelectedObject(),
                null);
        SessionFacadeCadastrarImplements facadeCadastrar = new SessionFacadeCadastrarImplements();
        SessionFacadeAlterarImplements facadeAlterar = new SessionFacadeAlterarImplements();
        if (facadeCadastrar.cadastrarCarne(carne)) {
            for (int i = 0; i < tableModel.getRowCount(); i++) {
                tableModel.getValue(i).setCarne(carne);
                facadeCadastrar.cadastrarMensalidade(tableModel.getValue(i));
            }
            carne.setPrestacaoList(tableModel.getData());
            if (facadeAlterar.alterarCarne(carne)) {
                Mensagens.Mensagem("Cadastrado com sucesso!");
            }
        }
    }

    private void alterarPessoa() throws Exception {
        SessionFacadeAlterarImplements facadeAlterar = new SessionFacadeAlterarImplements();
        if (facadeAlterar.alterarCarne(carne)) {
            Mensagens.Mensagem("Alterado com sucesso!");
        }
    }
}
